home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / tsr_asm.zip / TSR.ASM < prev   
Assembly Source File  |  1988-08-05  |  50KB  |  1,483 lines

  1. page    60,132
  2. ; Copyright 1987 by Thomas Brandenborg. All Rights Reserved
  3. ; Written for uploading to Compuserve Forums by
  4. ;
  5. ;       Thomas Brandenborg
  6. ;       Lundbyesgade 11
  7. ;       DK-8000 Aarhus C
  8. ;       DENMARK
  9. ;
  10. ; Modified to work under Lattice-C S model version 2.14
  11. ; might work under newer versions as well
  12. ; H.F. van Rietschote
  13. ;
  14. ;    You write cpopup() in Lattice-C and you have a popup
  15. ;    go and become TSR after calling intdos() with ax=0x3100 and dx=_TSIZE
  16. ;    but after this no more MALLOC(), also not indirect ia fopen() etc.
  17. ;    allowed.
  18.  
  19. DGROUP    GROUP    DATA
  20. DATA    SEGMENT    WORD    PUBLIC    'DATA'
  21.     ASSUME    DS:DGROUP
  22. DATA    ENDS
  23.  
  24. ;==============================================================================
  25. ; DEFINE BIOS DATA SEGMENT OFFSETS
  26. ;==============================================================================
  27.  
  28. BiosData    segment at 40h
  29.         org     17h
  30. KbFlag        label   byte            ;current shift status bits
  31.         org     18h
  32.  
  33. KbFlag1         label   byte            ;current key status of toggle keys
  34. BiosData        ends
  35.  
  36. ;==============================================================================
  37. ; DEFINE OFFSETS WITHIN BIOS EXTRA DATA SEGMENT
  38. ;==============================================================================
  39.  
  40. BiosXX          segment at 50h
  41.         org     0
  42. StatusByte      label   byte            ;PrtSc status
  43. BiosXX          ends
  44.  
  45. ErrPrtSc        equ     -1              ;err during last PrtSc
  46. InPrtSc         equ     1               ;PrtSc in progress
  47.  
  48. ;==============================================================================
  49. ; DEFINE OFFSETS WITHIN OUR PSP
  50. ;==============================================================================
  51.  
  52. PGROUP        GROUP    PROG
  53. PROG        SEGMENT    BYTE PUBLIC 'PROG'
  54.         public    tsr,ErrBeep,Bleep
  55.         extrn    cpopup:near
  56.         assume    cs:PGROUP, ds:nothing, es:nothing, ss:nothing
  57.  
  58. ;==============================================================================
  59. ; IDENTIFICATION CODES FOR THIS TSR (MUST BE UNIQUE FOR EACH CO-EXISTING TSR)
  60. ; HIGH BYTE OF GetId MUST NOT MATCH ANY AH REQUEST CODES FOR INT16H.
  61. ;==============================================================================
  62.  
  63. GetId           equ     'tc'            ;INT16h AX val to get MyId
  64. MyId            equ     'TC'            ;ID of this TSR
  65. SetAlarm    equ    'al'            ; set alarm, BX= # of min. to wait
  66.  
  67. ;==============================================================================
  68. ; FLAGS AND PTRS FOR RESIDENT HANDLING
  69. ;==============================================================================
  70.  
  71. TsrMode         db      0               ;bits for various modes
  72. InInt08         equ     1 SHL 0         ;timer0 tick handler
  73. InInt09         equ     1 SHL 1         ;keyboard handler
  74. InInt13         equ     1 SHL 2         ;BIOS disk I/O
  75. InInt28         equ     1 SHL 3         ;INT28 handler
  76. In28Call        equ     1 SHL 4         ;we have issued INT28
  77. InPopup         equ     1 SHL 5         ;popup routine activated
  78. NewDos          equ     1 SHL 6         ;DOS 2.x in use
  79. InDosClr        equ     1 SHL 7         ;InDos=0 at popup time
  80.  
  81. KeyMode         db      0               ;bits for hotkey status
  82. HotIsShift      equ     1 SHL 0         ;hotkey is shift state
  83. InHotMatch      equ     1 SHL 1         ;so far keys match hotkey seq
  84. HotKeyOn        equ     1 SHL 2         ;full hotkey pressed
  85.  
  86. InDosPtr        label   dword           ;seg:off of InDos flag
  87. InDosOff        dw      0
  88. InDosSeg        dw      0
  89.  
  90. CritErrPtr      label   dword           ;seg:off of CritErr flag
  91. CritErrOff      dw      0
  92. CritErrSeg      dw      0
  93.  
  94. ;==============================================================================
  95. ; DATA FOR INT09H HANDLER TO CHECK FOR HOTKEY COMBINATION
  96. ;==============================================================================
  97.  
  98. ; ------------  EQU'S FOR BIT SHIFTS WITHIN KEYBOARD FLAGS
  99.  
  100. InsState        equ     80h
  101. CapsState       equ     40h
  102. NumState        equ     20h
  103. ScrollState     equ     10h
  104. AltShift        equ     08h
  105. CtlShift        equ     04h
  106. LeftShift       equ     02h
  107. RightShift      equ     01h
  108.  
  109. InsShift        equ     80h
  110. CapsShift       equ     40h
  111. NumShift        equ     20h
  112. ScrollShift     equ     10h
  113. HoldState       equ     08h
  114.  
  115. ; ------------  SCAN CODES FOR VARIOUS SHIFT KEYS
  116.  
  117. LeftDown        equ     42              ;scan code of left shift key
  118. LeftUp          equ     LeftDown OR 80h
  119. RightDown       equ     54              ;scan code of right shift key
  120. RightUp         equ     RightDown OR 80h
  121. AltDown         equ     56              ;scan code of alt key
  122. AltUp           equ     AltDown OR 80h
  123. CtlDown         equ     29              ;scan code of ctrl key
  124. CtlUp           equ     CtlDown OR 80h
  125.  
  126. ; ------------  MISC KEYBOARD DATA
  127.  
  128. KbData          equ     60h             ;keyboard data input
  129.  
  130. ;==============================================================================
  131. ; TO USE A SHIFT KEY COMBINATION AS HOT KEY:
  132. ;  -    SET THE FLAG HotIsShift IN KeyMode
  133. ;  -    DEFINE THE SHIFT STATUS BITS IN THE VARIABLE HotKeyShift
  134. ;
  135. ; TO USE A SERIES OF SCAN CODES AS HOT KEY:
  136. ;       CLEAR THE FLAG HotIsShift IN KeyMode
  137. ;  -    INSERT THE MAKE AND BREAK SCAN CODES IN THE HotKeySeq STRING
  138. ;       NOTE:   WITH THIS DEMO IMPLEMENTATION YOU SHOULD NOT USE A HOT KEY
  139. ;               SEQUENCE WHICH PRODUCES A KEY IN THE BIOS KEYBOARD QUEUE,
  140. ;               SINCE THE KEY IS NOT REMOVED BEFORE CALLING THE POPUP ROUTINE.
  141. ;
  142. ; NOTE: HOTKEY TYPE AND CONTENTS OF HOTKEY VARIABLES MAY BE CHANGED AT RUN TIME
  143. ;==============================================================================
  144.  
  145. HotKeyShift     db      LeftShift OR RightShift ;shift state IF HotIsShift=FF
  146.  
  147. ; HotKeySeq       db      LeftDown,LeftUp,LeftDown,LeftUp
  148. HotKeySeq       db      LeftDown,LeftUp,RightDown,RightUp
  149. HotKeyLen       equ     $-HotKeySeq
  150. HotIndex        db      0               ;# key in seq to compare next
  151. BetweenKeys     db      0               ;timeout count between keys
  152. KeyTimeOut      equ     10              ;more ticks means not a hotkey
  153.  
  154. ;==============================================================================
  155. ; DATA FOR INT08H HANDLER TO CHECK FOR POPUP
  156. ;==============================================================================
  157.  
  158. SafeWait        db      0               ;count-down for safe popup
  159. MaxWait         equ     8               ;wait no more 8/18 sec
  160. MinLeft        dw    0            ; minutes left until alarm
  161. TicksDone    dw    0            ; Ticks counted in this minute
  162. Bleeping    dw    0            ; 1 means we are bleeping
  163.  
  164. ;==============================================================================
  165. ; PROCESS & SYSTEM DATA
  166. ;==============================================================================
  167.  
  168. OurSS           dw      0               ;stack for popup routine
  169. OurSP           dw      0
  170. OurES        dw    0
  171. OurBP        dw    0
  172. OurDS        dw    0
  173. DSLattice    dw    0        ; DS as in Lattice-C
  174.  
  175. OldSS           dw      0               ;old stack seg
  176. OldSP           dw      0               ;old stack off
  177. OldES        dw    0
  178. OldBP        dw    0
  179. OldDS        dw    0
  180.  
  181. OurPSP          dw      0               ;our PSP seg
  182. OldPSP          dw      0               ;old PSP seg
  183.  
  184. OldDTA          label   dword           ;seg:off of old DTA area
  185. OldDTAOff       dw      0
  186. OldDTASeg       dw      0
  187.  
  188. OurDTA          label   dword           ;seg:off of our DTA
  189. OurDTAOff       dw      0
  190. OurDTASeg       dw      0
  191.  
  192. OldBreak        db      0               ;old ctrl-break state
  193. OldExtErr       dw      3 dup (0)               ;AX,BX,CX of ext err
  194.  
  195. ;==============================================================================
  196. ; LOCATIONS FOR SAVED INTERRUPT VECTORS
  197. ;==============================================================================
  198.  
  199. OldInt08        label   dword           ;Timer0 loaded before this
  200. OldInt08Off     dw      0
  201. OldInt08Seg     dw      0
  202.  
  203. OldInt09        label   dword           ;Kb handler loadde before this
  204. OldInt09Off     dw      0
  205. OldInt09Seg     dw      0
  206.  
  207. OldInt13        label   dword           ;BIOS diskette I/O
  208. OldInt13Off     dw      0
  209. OldInt13Seg     dw      0
  210.  
  211. OldInt16        label   dword           ;BIOS kb Q-handler
  212. OldInt16Off     dw      0
  213. OldInt16Seg     dw      0
  214.  
  215. OldInt1B        label   dword           ;^break of process we steal
  216. OldInt1BOff     dw      0
  217. OldInt1BSeg     dw      0
  218.  
  219. OldI